{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 2022/10/11/week 08\n",
    "* python 课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "> 0. 代码的注释\n",
    "> 1. 用户输入\n",
    "> 2. 格式化的输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. 代码的注释"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">1.# 一般写在代码块的最上边，或者每一行代码的后面，用于代码思路的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author;蔡果果"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 2.\"注释内容\"，一般是注释代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 用户输入\n",
    "> 1.input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:caiguoguo\n",
      "密码:123456\n",
      "caiguoguo\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "# 登录系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:SVT\n",
      "密码:234456\n",
      "账号不存在或密码不正确!\n"
     ]
    }
   ],
   "source": [
    "# 登录系统 迭代1；增加了判断功能\n",
    "# 假设我们数据库有用户信息：账号:caiguoguo，密码:123456\n",
    "user1 = \"caiguoguo\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "# 情景一： 输入信息正确，登录成功\n",
    "if user1 == username and password1 == password:\n",
    "      print(\"欢迎\"+user1+\"登录！\")\n",
    "        \n",
    "# 情景二；账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:SVT\n",
      "密码:234478\n",
      "账号不存在或密码不正确!\n",
      "你还有2次尝试的而机会\n",
      "账号:BTS\n",
      "密码:130613\n",
      "账号不存在或密码不正确!\n",
      "你还有1次尝试的而机会\n",
      "账号:caiguoguo\n",
      "密码:123456\n",
      "欢迎caiguoguo登录！\n"
     ]
    }
   ],
   "source": [
    "# 登录系统 迭代2：增加循环功能\n",
    "# 假设我们数据库有用户信息：账号:caiguoguo，密码:123456\n",
    "user1 = \"caiguoguo\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1): # i 是一个 int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    # 情景一： 输入信息正确，登录成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录！\")\n",
    "        break # 终止循环\n",
    "    # 情景二；账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请一个小时后再来尝试\")\n",
    "         print(\"账号不存在或密码不正确!\")\n",
    "    print(\"你还有\"+str(i-1)+\"次尝试的而机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 格式化的输出\n",
    "> 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名;jk\n",
      "年龄;25\n",
      "工作;idol\n",
      "工资:100000000\n",
      "地区;韩国\n",
      "-----INFO OFjk-----\n",
      "年龄；25\n",
      "工资；idol\n",
      "工资；100000000\n",
      "地区；韩国\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统\n",
    "name = input(\"姓名;\")\n",
    "age = input(\"年龄;\")\n",
    "job = input(\"工作;\")\n",
    "salary = input(\"工资:\")\n",
    "reg = input(\"地区;\")\n",
    "\n",
    "info = '''-----INFO OF'''+ name +'''-----'''+'''\n",
    "年龄；'''+ age +'''\n",
    "工资；'''+ job +'''\n",
    "工资；'''+ salary +'''\n",
    "地区；'''+ reg\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method raw_input in module ipykernel.kernelbase:\n",
      "\n",
      "raw_input(prompt='') method of ipykernel.ipkernel.IPythonKernel instance\n",
      "    Forward raw_input to frontends\n",
      "    \n",
      "    Raises\n",
      "    ------\n",
      "    StdinNotImplentedError if active frontend doesn't support stdin.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(input)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "年龄;25\n",
      "25 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# input 作为用户输入，其都以字符串形式返回\n",
    "age = input(\"年龄;\")\n",
    "print(age,type(age))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名;jk\n",
      "年龄;25\n",
      "工作;idol\n",
      "工资:100000000\n",
      "地区;韩国\n",
      "-----INFO OF jk-----\n",
      "年龄；25 \n",
      "工资；idol\n",
      "工资；100000000\n",
      "地区；韩国\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二：占位符 %s,以此有序输入\n",
    "name = input(\"姓名;\")\n",
    "age = int(input(\"年龄;\")) # 强制将 str 转换成 int\n",
    "job = input(\"工作;\")\n",
    "salary = input(\"工资:\")\n",
    "reg = input(\"地区;\")\n",
    "\n",
    "info = '''-----INFO OF %s-----\n",
    "年龄；%s \n",
    "工作；%s\n",
    "工资；%s\n",
    "地区；%s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名;jk\n",
      "年龄;25\n",
      "工作;idol\n",
      "工资:100000000\n",
      "地区;韩国\n",
      "-----INFO OF 25-----\n",
      "年龄；25\n",
      "工作：idol\n",
      "工资；100000000\n",
      "地区；韩国\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三：format() 格式化输出函数\n",
    "name = input(\"姓名;\")\n",
    "age = int(input(\"年龄;\")) # 强制将 str 转换成 int\n",
    "job = input(\"工作;\")\n",
    "salary = input(\"工资:\")\n",
    "reg = input(\"地区;\")\n",
    "\n",
    "info = '''-----INFO OF {年龄}-----\n",
    "年龄；{年龄}\n",
    "工作：{工作}\n",
    "工资；{工资}\n",
    "地区；{地区}'''.format(年龄 = age, 工作 = job,工资 = salary,地区 = reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-1-a39f34d1c1d7>, line 6)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-1-a39f34d1c1d7>\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m    balance = int(input（\"支付宝余额：\")）\u001b[0m\n\u001b[1;37m                       ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "Commodity =[ ['Iphone14' ,5000],\n",
    "            ['Iphone pro14', 8999],\n",
    "            ['Macbook', 10000]]\n",
    "\n",
    "\n",
    "balance = int(input（\"支付宝余额：\")）\n",
    "Shopping cart =[]\n",
    "\n",
    "print (Commodity)\n",
    "\n",
    "#循环退出条件，为1时退出while谓环\n",
    "quit =0\n",
    "\n",
    "while(quit!=1):\n",
    "    print(“----购物车小程序----\")\n",
    "if len (commondity) < 1:\n",
    "   print(“商品己售空，程序退出”)\n",
    "break\n",
    "          \n",
    "for index,item in enumerate (commondity):\n",
    "print (index+l, item)\n",
    "          \n",
    "#number商品编号，默认为0， number=o\n",
    "#price为商品价格，默认为0, price=o\n",
    "          \n",
    "for index, item in enumerate (commodity) :\n",
    "number=int(input（“输入你要买的商品编号，输入-1则退出“)）\n",
    "1f number == -1：\n",
    "    quit = 1\n",
    "break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
